import { BasicColumn } from '/@/components/Table/src/types/table';
import { FormSchema } from '/@/components/Table';
import dayjs from 'dayjs';
function getDays(startDateString, endDateString) {
  const start = new Date(startDateString);
  const end = new Date(endDateString);
  const millisecondsPerDay = 1000 * 60 * 60 * 24;
  // 一天的毫秒数
  const millisecondsDiff = end.getTime() - start.getTime();
  // 获取毫秒差值
  const daysDiff = Math.ceil(millisecondsDiff / millisecondsPerDay);
  // 计算相差的天数
  return daysDiff;
}

export function getBasicColumns(): BasicColumn[] {
  return [
    {
      title: '终端类型',
      dataIndex: 'ZDLX',
      width: 80,
      customRender({ record }) {
        if (record.orderDetailDto.createBy === 'API接口') {
          return 'APP';
        } else {
          return '票务';
        }
      },
    },
    {
      title: '预订时间',
      dataIndex: 'createTime',
      customRender({ record }) {
        if (record.status === 'CANCEL')
          return dayjs(record.orderDetailDto.lastOptime).format('YYYY-MM-DD HH:mm:ss');
        else return dayjs(record.orderDetailDto.createTime).format('YYYY-MM-DD HH:mm:ss');
      },
      width: 180,
    },
    {
      title: '预订人',
      dataIndex: 'YDR',
      customRender({ record }) {
        return record.orderDetailDto.names;
      },
      width: 80,
    },
    {
      title: '出差申请单号',
      dataIndex: 'CCSQDH',
      width: 200,
      customRender({}) {
        return '-';
      },
    },
    {
      title: '订单号',
      dataIndex: 'DDH',
      customRender({ record }) {
        return record.orderId;
      },
      width: 200,
    },
    {
      title: '预订人编号',
      dataIndex: 'accountNo',
      width: 100,
    },
    {
      title: '出差人数',
      dataIndex: 'chucairenshu',
      width: 100,
      customRender: () => {
        return 1;
      },
    },
    {
      title: '入住人',
      dataIndex: 'names',
      width: 80,
    },
    {
      title: '联系人电话',
      dataIndex: 'mobile',
      customRender({ record }) {
        return record.orderDetailDto.contact.mobile;
      },
    },
    {
      title: '酒店名称',
      dataIndex: 'hotelName',
      customRender({ record }) {
        return record.orderDetailDto.hotelName;
      },
      width: 400,
    },
    {
      title: '城市',
      dataIndex: 'geoName',
      customRender({ record }) {
        return record.orderDetailDto.geoName;
      },
      width: 100,
    },
    {
      title: '入住日期',
      dataIndex: 'arrivalDate',
      width: 100,
      customRender({ record }) {
        return record.arrivalDate ? dayjs(record.arrivalDate).format('YYYY-MM-DD') : '-';
      },
    },
    {
      title: '离店日期',
      dataIndex: 'departureDate',
      width: 100,
      customRender({ record }) {
        return record.departureDate ? dayjs(record.departureDate).format('YYYY-MM-DD') : '-';
      },
    },
    {
      title: '房间数',
      dataIndex: 'roomCount',
      customRender({ record }) {
        return record.orderDetailDto.roomCount;
      },
      width: 60,
    },
    {
      title: '间夜数',
      dataIndex: 'jianyeshu',
      width: 60,
      customRender: ({ record }) => {
        return getDays(record.arrivalDate, record.departureDate);
      },
    },
    {
      title: '酒店级别',
      dataIndex: 'hotelLeave',
      width: 80,
      customRender: ({ record }) => {
        return record.orderDetailDto.assist.hotelCategory
          ? record.orderDetailDto.assist.hotelCategory
          : '-';
      },
    },
    {
      title: '房型',
      dataIndex: 'roomName',
      customRender({ record }) {
        return record.orderDetailDto.roomName;
      },
    },
    {
      title: '订单金额',
      dataIndex: 'money',
      customRender({ record }) {
        return record.status === 'CANCEL'
          ? -record.orderDetailDto.totalPay
          : record.orderDetailDto.totalPay;
      },
      width: 80,
    },
    {
      title: '日均价',
      dataIndex: 'priceAvg',
      width: 80,
      customRender: ({ record }) => {
        return record.status === 'CANCEL'
          ? (
              -record.orderDetailDto.totalPay / getDays(record.arrivalDate, record.departureDate)
            ).toFixed(2)
          : (
              record.orderDetailDto.totalPay / getDays(record.arrivalDate, record.departureDate)
            ).toFixed(2);
        // return record.orderDetailDto.totalPay / getDays(record.arrivalDate, record.departureDate);
      },
    },
    {
      title: '退款金额',
      dataIndex: 'TKJE',
      width: 80,
      customRender({ record }) {
        return record.status === 'CANCEL' ? record.orderDetailDto.totalPay : '0';
      },
    },
    {
      title: '增值费用',
      dataIndex: '1',
      width: 80,
      customRender({}) {
        return 0;
      },
    },
    {
      title: '其他费用',
      dataIndex: '2',
      width: 80,
      customRender({}) {
        return 0;
      },
    },
    {
      title: '房损金额',
      dataIndex: '3',
      width: 80,
      customRender({}) {
        return 0;
      },
    },
    {
      title: '取消订单费',
      dataIndex: '4',
      width: 110,
      customRender({}) {
        return 0;
      },
    },
    {
      title: '房费增加',
      dataIndex: '5',
      width: 80,
      customRender({}) {
        return 0;
      },
    },
    {
      title: '集团托管服务费',
      dataIndex: '6',
      width: 120,
      customRender({}) {
        return 0;
      },
    },
    {
      title: '单体托管服务费',
      dataIndex: '7',
      width: 120,
      customRender({}) {
        return 0;
      },
    },
    {
      title: '售票处服务费',
      dataIndex: '8',
      width: 120,
      customRender({}) {
        return 0;
      },
    },
    {
      title: '深白云扣款',
      dataIndex: 'SBYKK',
      width: 110,
      customRender({ record }) {
        return record.status === 'CANCEL'
          ? -record.orderDetailDto.totalPay
          : record.orderDetailDto.totalPay;
      },
    },
    {
      title: '应收总计',
      dataIndex: 'YSZJ',
      width: 80,
      customRender({ record }) {
        return record.status === 'CANCEL'
          ? -record.orderDetailDto.totalPay
          : record.orderDetailDto.totalPay;
      },
    },
    {
      title: '总金额包含服务费',
      dataIndex: 'ZJEBHFWD',
      customRender({ record }) {
        return record.status === 'CANCEL'
          ? -record.orderDetailDto.totalPay
          : record.orderDetailDto.totalPay;
      },
    },
    {
      title: '订单情况',
      dataIndex: 'DDQK',
      width: 100,
      customRender: ({ record }) => {
        if (record.status === 'WAIT_CONFIRM') {
          return '等待确认';
        } else if (record.status === 'WAIT_PAY') {
          return '等待支付';
        } else if (record.status === 'CONFIRM') {
          return '已确认';
        } else if (record.status === 'NO_SHOW') {
          return '未入住';
        } else if (record.status === 'CHECK_OUT') {
          return '已离店';
        } else if (record.status === 'CANCEL') {
          return '已取消';
        } else if (record.status === 'CHECK_IN	') {
          return '已入住';
        } else {
          return '无效';
        }
      },
    },
    {
      title: '渠道',
      dataIndex: 'channelName',
      customRender({ record }) {
        return record.orderDetailDto.channelName;
      },
    },
    {
      title: '提前离店/延住',
      dataIndex: '40',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '支付方式',
      dataIndex: 'payType',
      width: 100,
      customRender: () => {
        return '';
      },
    },
    {
      title: '结算状态',
      dataIndex: '9',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '成本中心',
      dataIndex: 'costDeptName',
      customRender({ record }) {
        return record.orderDetailDto.customers[0].costDeptName
          ? record.orderDetailDto.customers[0].costDeptName
          : '-';
      },
    },
    {
      title: 'OA申请单号',
      dataIndex: 'voucherId',
      width: 200,
      customRender({}) {
        return '-';
      },
    },
    {
      title: '业务经理',
      dataIndex: 'busiManage',
      width: 80,
      customRender({ record }) {
        return record.orderDetailDto.busiManage ? record.orderDetailDto.busiManage : '-';
      },
    },
    {
      title: '服务商名称',
      dataIndex: '10',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '供应商单号',
      dataIndex: 'GYSDH',
      customRender({ record }) {
        return record.orderDetailDto.serverId;
      },
    },
    {
      title: '订单状态',
      dataIndex: 'status',
      customRender: ({ text }) => {
        if (text === 'WAIT_CONFIRM') {
          return '等待确认';
        } else if (text === 'WAIT_PAY') {
          return '等待支付';
        } else if (text === 'CONFIRM') {
          return '已确认';
        } else if (text === 'NO_SHOW') {
          return '未入住';
        } else if (text === 'CHECK_OUT') {
          return '已离店';
        } else if (text === 'CANCEL') {
          return '已取消';
        } else if (text === 'CHECK_IN	') {
          return '已入住';
        } else {
          return '无效';
        }
      },
    },
    {
      title: '房损类型',
      dataIndex: '11',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '订单类型',
      dataIndex: 'DDLX',
      customRender() {
        return '国内酒店';
      },
    },
    {
      title: '预订人部门',
      dataIndex: 'YDRBM',
      customRender({ record }) {
        if (record.examineApprove != null) {
          return record.examineApprove.departmentId;
        }
      },
    },
    {
      title: '预订类型',
      dataIndex: 'travelType',
      width: 100,
      customRender: () => {
        return '无审批单';
      },
    },
    {
      title: '个人支付金额',
      dataIndex: 'amount',
      customRender({ record }) {
        return record.status === 'CANCEL' ? -record.amount : record.amount;
      },
    },
    {
      title: '个人退款金额',
      dataIndex: 'refundAmount',
      customRender({ record }) {
        if (record.status === 'CANCEL') {
          return record.amount;
        } else {
          return '0';
        }
      },
    },
    {
      title: '公司支付金额',
      dataIndex: '14',
      customRender({}) {
        return 0;
      },
    },
    {
      title: '公司退款金额',
      dataIndex: '15',
      customRender({}) {
        return 0;
      },
    },
    {
      title: '交易流水号',
      dataIndex: 'serialNum',
      customRender({ record }) {
        return record.serialNum ? record.serialNum : '-';
      },
    },
    {
      title: '费用承担部门',
      dataIndex: '17',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '项目编号',
      dataIndex: '18',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '项目名称',
      dataIndex: '19',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '差旅事项',
      dataIndex: '20',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '超标原因',
      dataIndex: '21',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '超标金额',
      dataIndex: '22',
      customRender({}) {
        return 0;
      },
    },
    {
      title: '超标描述',
      dataIndex: '23',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '费用类型',
      dataIndex: '24',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '差旅授权号',
      dataIndex: '25',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '审批状态',
      dataIndex: '26',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '给审批人留言',
      dataIndex: '27',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '审批组1类型',
      dataIndex: '28',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '审批组1审批人',
      dataIndex: '29',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '审批组2类型',
      dataIndex: '30',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '审批组2审批人',
      dataIndex: '31',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '审批组3类型',
      dataIndex: '32',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '审批组3审批人',
      dataIndex: '33',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '审批组4类型',
      dataIndex: '34',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '审批组4审批人',
      dataIndex: '35',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '入住人部门',
      dataIndex: 'RZRBM',
      customRender({ record }) {
        return record.examineApprove ? record.examineApprove.departmentId : '-';
      },
    },
    {
      title: '确认号',
      dataIndex: '36',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '酒店集团',
      dataIndex: '37',
      customRender({}) {
        return '-';
      },
    },
    {
      title: '差标金额',
      dataIndex: '38',
      customRender({}) {
        return 0;
      },
    },
  ];
}
export const searchFormSchema: FormSchema[] = [
  {
    field: 'travelType',
    label: '预定方式',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      placeholder: '',
      options: [{ label: '无审批单', value: '1' }],
      style: 'width: 140px',
    },
  },
  {
    field: 'employeeNo',
    label: '职工编号',
    component: 'Input',
    colProps: { span: 4 },
    componentProps: {
      placeholder: ' ',
      style: 'width: 140px',
    },
  },
  {
    field: 'names',
    label: '职工姓名',
    component: 'Input',
    colProps: { span: 4 },
    componentProps: {
      placeholder: ' ',
      style: 'width: 140px',
    },
  },
  {
    field: 'examineApproveNo',
    label: '审批单编号',
    component: 'Input',
    colProps: { span: 4 },
    componentProps: {
      placeholder: ' ',
      style: 'width: 140px',
    },
  },
  {
    field: 'geoName',
    label: '城市',
    component: 'Input',
    colProps: { span: 4 },
    componentProps: {
      placeholder: ' ',
      style: 'width: 140px',
    },
  },
  {
    field: 'isTravelStandard',
    label: '是否超标',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      placeholder: '',
      options: [{ label: '未超标', value: '0' }],
      style: 'width: 140px',
    },
  },
  {
    field: 'createTime',
    component: 'RangePicker',
    label: '预订日期',
    colProps: {
      span: 8,
    },
    componentProps: {
      placeholder: ['预订日期起', '预订日期止'],
      style: 'width: 410px',
    },
    defaultValue: [getCurrentDataL(), getCurrentDataR()],
  },
  {
    field: 'arrivalDate',
    component: 'RangePicker',
    label: '入店日期',
    colProps: {
      span: 8,
    },
    componentProps: {
      placeholder: ['入店日期起', '入店日期止'],
      style: 'width:410px',
    },
  },
  {
    field: 'departureDateDate',
    component: 'RangePicker',
    label: '离店日期',
    colProps: {
      span: 8,
    },
    componentProps: {
      placeholder: ['离店日期起', '离店日期止'],
      style: 'width: 410px',
    },
  },
];
//获得当前年份4位年
function getCurrentDataL() {
  return dayjs(dayjs().year().toString() + '-' + Number(dayjs().month()) + '-15').format(
    'YYYY-MM-DD',
  );
}
function getCurrentDataR() {
  // return new Date().toLocaleDateString();
  return dayjs(dayjs().year().toString() + '-' + Number(dayjs().month() + 1) + '-16').format(
    'YYYY-MM-DD',
  );
}
